package com.cozy.android.sdk;

import android.app.Activity;
import android.content.Context;
import android.os.VibrationEffect;
import android.os.Vibrator;

import com.cozy.android.sdk.bridge.CozyUnityBridge;

public class CozySDK implements AA {

    public static void aCozyPlayAd(String adSource){
        CozyAdSdk.showAd(adSource);
    }

    public static void aCozyInit(Activity activity){
        CozySDKManager.getInstance().init(activity);
    }

    //necessary 每次启动调用一次，不同意协议不调用，首次在load之前调用
    public static void aCozyInterInit(){
        CozySDKManager.getInstance().interInit();
    }

    public static void aCozyOnVibrator(String durationMs, int amplitude){
        try {
            Activity activity = CozyUnityBridge.mainGameActivity.get();
            if (activity == null) return;
            Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
            if (vibrator == null || !vibrator.hasVibrator()) return;

            // API 26+ 支持自定义震动强度
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
                VibrationEffect effect = VibrationEffect.createOneShot(Long.parseLong(durationMs), amplitude);
                vibrator.vibrate(effect);
            } else {
                // 旧版系统不支持设置强度，只能设置时长
                vibrator.vibrate(Long.parseLong(durationMs));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

